package com.sc.nft.entity.vo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil;
import com.sc.nft.entity.CollectionGift;
import com.sc.nft.enums.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

/**
 * 藏品表(sc_digital_collection)实体类
 *
 * @author zxy
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2022-06-03 15:46:04
 */
@Data

public class DigitalCollectionVO {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("id")
    private Long id;

    @ApiModelProperty("等级")
    private Integer showLevel;
    @ApiModelProperty("等级名称")
    private String showLevelName;

    @ApiModelProperty("详情页图")
    private String productDetailPicture;

    @ApiModelProperty("一级标题")
    private String firstTitle;

    @ApiModelProperty("缩略图")
    private String creationContent;

    @ApiModelProperty("uuid")
    private String digitalCollectionUuid;

    @ApiModelProperty("系列id")
    private Long catenaId;

    @ApiModelProperty("系列名称")
    private String catenaName;

    @ApiModelProperty("创作者Id")
    private Long userCreatorId;

    @ApiModelProperty("创作者名称")
    private String userCreatorName;

    @ApiModelProperty("是否是可合成藏品")
    private Boolean isSynthesis;

    @ApiModelProperty("是否是特权藏品")
    private Boolean isPrivilege;

    @ApiModelProperty("特权藏品等级")
    private Integer privilegeLevel;

    @ApiModelProperty("是否可以转增")
    private Boolean isGive;

    @ApiModelProperty("藏品总库存")
    private Integer sumCount;

    @ApiModelProperty("可用库存")
    private Integer usableCount;

    @ApiModelProperty("锁仓天数")
    private Integer lockupDays;

    @ApiModelProperty("商品介绍")
    @NotNull(message = "商品介绍不能为空")
    private String productPresentation;

    @ApiModelProperty("特权介绍")
    private String privilegePresentation;

    @ApiModelProperty("详情页图类型 1 图片 2:动图 3:3d模型")
    private Integer productDetailPictureType;
    @ApiModelProperty("发行价")
    private BigDecimal issuePrice;

    @ApiModelProperty("3d模型id")
    private String threeModelId;

    @ApiModelProperty("流通数量")
    private Integer circulationNum;

    @ApiModelProperty("防囤数量")
    private Integer antiHoardCount;

    @ApiModelProperty("防囤收益比例")
    private BigDecimal antiHoardRatio;

    @ApiModelProperty("跳转详情")
    private String skipUrl;

    /**
     * 链状态 0:历史藏品(不处理) 1:等待上链 2:上链中 3:上链完成
     */
    private CollectionChainStatusEnum chainStatus;

    @ApiModelProperty("INIT:初始化 DEPLOYING:部署中 DEPLOY_SUCCESS:部署成功")
    private CollectionContractStatusEnum contractStatus;

    @ApiModelProperty("藏品分类: 1:衍生藏品 2:版权藏品 3:生态孵化")
    private DigitalMarketTypeEnum collection_type;

    @ApiModelProperty("藏品属性")
    private Long collectionSearch;

    @ApiModelProperty("藏品属性名称")
    private String collectionSearchName;

    @ApiModelProperty("赠送配置")
    private CollectionGiftVO collectionGiftVO;

    @ApiModelProperty("是否可以转增到玛特钱包")
    private Boolean isGiveImeta;

    @ApiModelProperty("原创类型: MATE_UNIVERSE:玛特宇宙 MATE_WALLET:玛特钱包")
    private CollectionOriginalTypeEnum originalType;

    @ApiModelProperty("跨链赠送配置")
    @Valid
    private CollectionGiftVO mateWalletGiveGiftVO = new CollectionGiftVO();

    @ApiModelProperty("关联状态 1:未关联 2:已关联,可修改 3:已关联,不可修改")
    private Integer linkStatus;

    @ApiModelProperty("流通类型")
    private CirculationTypeEnum circulationType;

    @ApiModelProperty(value = "上链费")
    private BigDecimal gasCost;


    public void conversionConfiguration(List<CollectionGift> collectionGifts) {
        if (CollUtil.isEmpty(collectionGifts)) {
            return;
        }
        if (BeanUtil.isEmpty(this.collectionGiftVO)) {
            this.collectionGiftVO = new CollectionGiftVO();
        }
        collectionGifts.forEach(propGift -> {
            if (propGift.getConsumeType().equals(1)) {
                this.collectionGiftVO.setDebrisConsume(NumberUtil.toBigDecimal(propGift.getQuantityConsume()).setScale(2, RoundingMode.DOWN).toString());
            } else if (propGift.getConsumeType().equals(2)) {
                this.collectionGiftVO.setBalanceConsume(NumberUtil.toBigDecimal(propGift.getQuantityConsume()).setScale(2, RoundingMode.DOWN).toString());
            } else {
                this.collectionGiftVO.setEcologyConsume(NumberUtil.toBigDecimal(propGift.getQuantityConsume()).setScale(2, RoundingMode.DOWN).toString());
            }
        });
    }

    public void conversionMateWalletGiveGiftVO(List<CollectionGift> collectionGifts) {
        if (CollUtil.isEmpty(collectionGifts)) {
            return;
        }
        if (BeanUtil.isEmpty(this.mateWalletGiveGiftVO)) {
            this.mateWalletGiveGiftVO = new CollectionGiftVO();
        }
        collectionGifts.forEach(propGift -> {
            if (propGift.getConsumeType().equals(1)) {
                this.mateWalletGiveGiftVO.setDebrisConsume(NumberUtil.toBigDecimal(propGift.getQuantityConsume()).setScale(2, RoundingMode.DOWN).toString());
            } else if (propGift.getConsumeType().equals(2)) {
                this.mateWalletGiveGiftVO.setBalanceConsume(NumberUtil.toBigDecimal(propGift.getQuantityConsume()).setScale(2, RoundingMode.DOWN).toString());
            } else {
                this.mateWalletGiveGiftVO.setEcologyConsume(NumberUtil.toBigDecimal(propGift.getQuantityConsume()).setScale(2, RoundingMode.DOWN).toString());
            }
        });
    }
}